import request from '@/utils/request'

export const profileGetService = () => {
  return request.get('/user/api/me/profile');
}

export const profilePutService = ({name, bio}) => {
  return request.put('/user/api/me/profile', {name, bio});
}

export const profileGetBasicService = () => {
  return request.get('/user/api/me/profile/basic');
}

export const profilePostAvatarService = (avatarFile, onProgress) => {
  const formData = new FormData();
  formData.append("avatar", avatarFile);

  return request.post('/user/api/me/profile/avatar', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    onUploadProgress: (event) => {
      // 处理进度（百分比）
      if (event.total) {
        onProgress({ percent: (event.loaded / event.total) * 100 });
      }
    }
  });
}

export const profilePutAvatarRandomlyService = () => {
  return request.put('/user/api/me/profile/random-avatar');
}